package com.fiberhome.app.network;

import android.content.Context;

import com.fiberhome.app.network.cache.CacheUtil;
import com.fiberhome.app.network.download.DownloadManager;
import com.fiberhome.app.network.http.HttpFactory;
import com.fiberhome.app.network.socket.SocketFactory;
import com.fiberhome.app.network.upload.UploadManager;

/**
 * Created by Deed on 2018/1/16.
 */

public class NetUtil {
    private static HttpFactory httpFactory;
    private static HttpFactory httpsFactory;
    private static SocketFactory socketFactory;

    /**
     * Please call NetUtil.init(context) on the method onCreate of your self-defined Application
     * @param context an application context
     */
    public static void init(Context context) {
        CacheUtil.myCache().init(context);
        DownloadManager.getInstance().init(context);
    }

    /**
     *
     * @return HttpFactory
     */
    public static HttpFactory http() {
        if (httpFactory == null) {
            httpFactory = new HttpFactory(false);
        }
        return httpFactory;
    }

    /**
     *
     * @return HttpFactory
     */
    public static HttpFactory https() {
        if (httpsFactory == null) {
            httpsFactory = new HttpFactory(true);
        }
        return httpsFactory;
    }

    /**
     *
     * @return SocketFactory
     */
    public static SocketFactory socket() {
        if (socketFactory == null) {
            socketFactory = new SocketFactory();
        }

        return socketFactory;
    }

    /**
     *
     * @return DownloadManager
     */
    public static DownloadManager download() {
        return DownloadManager.getInstance();
    }

    /**
     *
     * @return UploadManager
     */
    public static UploadManager upload() {
        return UploadManager.getInstance();
    }
}
